
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>xml解析 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="json-reporter.html" />
    
    
    <link rel="prev" href="http.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">----安卓 UI----</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="view.html">
            
                <a href="view.html">
            
                    
                    自定义控件和measure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="canvas-paint.html">
            
                <a href="canvas-paint.html">
            
                    
                    draw和canvas，paint详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="anim.html">
            
                <a href="anim.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="notify.html">
            
                <a href="notify.html">
            
                    
                    notify系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="loading.html">
            
                <a href="loading.html">
            
                    
                    loading系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="status-ui.html">
            
                <a href="status-ui.html">
            
                    
                    StatusUI系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="touch-scroll.html">
            
                <a href="touch-scroll.html">
            
                    
                    滑动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="layout.html">
            
                <a href="layout.html">
            
                    
                    Layout
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="textview.html">
            
                <a href="textview.html">
            
                    
                    TextView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="drawable.html">
            
                <a href="drawable.html">
            
                    
                    Drawable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="item-template.html">
            
                <a href="item-template.html">
            
                    
                    列表Adapter模板化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="recyclerview.html">
            
                <a href="recyclerview.html">
            
                    
                    RecyclerView全解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="design.html">
            
                <a href="design.html">
            
                    
                    MeterialDesign详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="component.html">
            
                <a href="component.html">
            
                    
                    AyoComponent基础库--Activity和Fragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="systembartint.html">
            
                <a href="systembartint.html">
            
                    
                    SystembarTint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="permission-ask.html">
            
                <a href="permission-ask.html">
            
                    
                    权限控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="keyboard.html">
            
                <a href="keyboard.html">
            
                    
                    小键盘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="notification.html">
            
                <a href="notification.html">
            
                    
                    Notification
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----安卓 foundation----</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="mvp.html">
            
                <a href="mvp.html">
            
                    
                    MVP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="rxjava.html">
            
                <a href="rxjava.html">
            
                    
                    RxJava
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="lang.html">
            
                <a href="lang.html">
            
                    
                    常用工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="http.html">
            
                <a href="http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.5" data-path="xml.html">
            
                <a href="xml.html">
            
                    
                    xml解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="json-reporter.html">
            
                <a href="json-reporter.html">
            
                    
                    Json解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="inject.html">
            
                <a href="inject.html">
            
                    
                    ButterKnife
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="thread.html">
            
                <a href="thread.html">
            
                    
                    安卓线程和looper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="process.html">
            
                <a href="process.html">
            
                    
                    多进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="eventbus.html">
            
                <a href="eventbus.html">
            
                    
                    EventBus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="db.html">
            
                <a href="db.html">
            
                    
                    数据库和ContentProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="job.html">
            
                <a href="job.html">
            
                    
                    定时任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="service.html">
            
                <a href="service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="opt-mem.html">
            
                <a href="opt-mem.html">
            
                    
                    内存优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="opt-network.html">
            
                <a href="opt-network.html">
            
                    
                    网络优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="opt-anr.html">
            
                <a href="opt-anr.html">
            
                    
                    anr排查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="opt-ui.html">
            
                <a href="opt-ui.html">
            
                    
                    UI卡顿优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.18" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    启动优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20" data-path="hotfix.html">
            
                <a href="hotfix.html">
            
                    
                    热补丁混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.21" data-path="aar.html">
            
                <a href="aar.html">
            
                    
                    aar相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.22" data-path="route.html">
            
                <a href="route.html">
            
                    
                    Route路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.23" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    分模块，组件化，插件化
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----Gradle----</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="gradle.html">
            
                <a href="gradle.html">
            
                    
                    gradle基本配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="gradle-plugin.html">
            
                <a href="gradle-plugin.html">
            
                    
                    gradle插件开发
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----工具----</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="repos.html">
            
                <a href="repos.html">
            
                    
                    优秀博客，开源项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="packs.html">
            
                <a href="packs.html">
            
                    
                    自动打包，多渠道打包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="gist.html">
            
                <a href="gist.html">
            
                    
                    代码片段和常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="stetho.html">
            
                <a href="stetho.html">
            
                    
                    stetho
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="fabric.html">
            
                <a href="fabric.html">
            
                    
                    fabric
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="app-update.html">
            
                <a href="app-update.html">
            
                    
                    自动升级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="bugsnags.html">
            
                <a href="bugsnags.html">
            
                    
                    日志和崩溃统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="mail.html">
            
                <a href="mail.html">
            
                    
                    发邮件辅助接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="socail.html">
            
                <a href="socail.html">
            
                    
                    第三方登录和分享
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="pay-alipay.html">
            
                <a href="pay-alipay.html">
            
                    
                    支付宝支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="pay-wx.html">
            
                <a href="pay-wx.html">
            
                    
                    微信支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="umeng.html">
            
                <a href="umeng.html">
            
                    
                    友盟统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="push-jpush.html">
            
                <a href="push-jpush.html">
            
                    
                    推送-极光
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="push-xiaomi.html">
            
                <a href="push-xiaomi.html">
            
                    
                    推送-小米
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >xml解析</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="xml&#x89E3;&#x6790;">xml&#x89E3;&#x6790;</h1>
<h1 id="xml&#x89E3;&#x6790;">XML&#x89E3;&#x6790;</h1>
<ul>
<li>3&#x79CD;&#x89E3;&#x6790;&#x65B9;&#x5F0F;<ul>
<li>DOM&#xFF1A;&#x4E00;&#x6B21;&#x6027;&#x52A0;&#x8F7D;&#xFF0C;&#x8017;&#x5185;&#x5B58;&#xFF0C;&#x4F46;&#x63A5;&#x53E3;&#x6BD4;&#x8F83;&#x53CB;&#x597D;</li>
<li>SAX&#xFF1A;Simple API for XML&#xFF0C;&#x9010;&#x884C;&#x626B;&#x63CF;&#xFF0C;&#x53EF;&#x4EE5;&#x505A;&#x5230;&#x8FB9;&#x626B;&#x63CF;&#x8FB9;&#x89E3;&#x6790;&#xFF0C;&#x4E8B;&#x4EF6;&#x9A71;&#x52A8;</li>
<li>PULL</li>
</ul>
</li>
</ul>
<p>&#x672C;&#x8282;&#x5185;&#x5BB9;&#x8BF7;&#x53C2;&#x8003;com.ayo.sample.xml.DemoXmlActivity</p>
<h4 id="">#</h4>
<p>&#x6A21;&#x677F;xml&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">xml_api_reply</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">weather</span> <span class="hljs-attr">module_id</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">tab_id</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">mobile_row</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">mobile_zipped</span>=<span class="hljs-string">&quot;1&quot;</span> <span class="hljs-attr">row</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">section</span>=<span class="hljs-string">&quot;0&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">forecast_information</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">city</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;Beijing, Beijing&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">postal_code</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;beijing&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">latitude_e6</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">longitude_e6</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">forecast_date</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;2012-07-24&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">current_date_time</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;2012-07-24 15:30:00 +0000&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">unit_system</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;SI&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">forecast_information</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">current_conditions</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">condition</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x591A;&#x4E91;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">temp_f</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;77&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">temp_c</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;25&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">humidity</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x6E7F;&#x5EA6;&#xFF1A; 78%&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">icon</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;/ig/images/weather/cn_cloudy.gif&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">wind_condition</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x98CE;&#x5411;&#xFF1A; &#x4E1C;&#x5317;&#x3001;&#x98CE;&#x901F;&#xFF1A;2 &#x7C73;/&#x79D2;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">current_conditions</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">forecast_conditions</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">day_of_week</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x5468;&#x4E8C;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">low</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;22&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">high</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;30&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">icon</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;/ig/images/weather/cn_cloudy.gif&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">condition</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x591A;&#x4E91;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">forecast_conditions</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">forecast_conditions</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">day_of_week</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x5468;&#x4E09;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">low</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;24&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">high</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;30&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">icon</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;/ig/images/weather/chance_of_rain.gif&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">condition</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x53EF;&#x80FD;&#x6709;&#x96E8;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">forecast_conditions</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">forecast_conditions</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">day_of_week</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x5468;&#x56DB;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">low</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;25&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">high</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;29&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">icon</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;/ig/images/weather/thunderstorm.gif&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">condition</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x96F7;&#x9635;&#x96E8;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">forecast_conditions</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">forecast_conditions</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">day_of_week</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x5468;&#x4E94;&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">low</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;24&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">high</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;31&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">icon</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;/ig/images/weather/chance_of_storm.gif&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">condition</span> <span class="hljs-attr">data</span>=<span class="hljs-string">&quot;&#x53EF;&#x80FD;&#x6709;&#x66B4;&#x98CE;&#x96E8;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">forecast_conditions</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">weather</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">xml_api_reply</span>&gt;</span>
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String xml = <span class="hljs-string">&quot;&lt;xml_api_reply version=\&quot;1\&quot;&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;    &lt;weather module_id=\&quot;0\&quot; tab_id=\&quot;0\&quot; mobile_row=\&quot;0\&quot; mobile_zipped=\&quot;1\&quot; row=\&quot;0\&quot; section=\&quot;0\&quot;&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;forecast_information&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;city data=\&quot;Beijing, Beijing\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;postal_code data=\&quot;beijing\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;latitude_e6 data=\&quot;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;longitude_e6 data=\&quot;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;forecast_date data=\&quot;2012-07-24\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;current_date_time data=\&quot;2012-07-24 15:30:00 +0000\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;unit_system data=\&quot;SI\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;/forecast_information&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;current_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;condition data=\&quot;&#x591A;&#x4E91;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;temp_f data=\&quot;77\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;temp_c data=\&quot;25\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;humidity data=\&quot;&#x6E7F;&#x5EA6;&#xFF1A; 78%\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;icon data=\&quot;/ig/images/weather/cn_cloudy.gif\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;wind_condition data=\&quot;&#x98CE;&#x5411;&#xFF1A; &#x4E1C;&#x5317;&#x3001;&#x98CE;&#x901F;&#xFF1A;2 &#x7C73;/&#x79D2;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;/current_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;day_of_week data=\&quot;&#x5468;&#x4E8C;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;low data=\&quot;22\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;high data=\&quot;30\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;icon data=\&quot;/ig/images/weather/cn_cloudy.gif\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;condition data=\&quot;&#x591A;&#x4E91;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;/forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;day_of_week data=\&quot;&#x5468;&#x4E09;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;low data=\&quot;24\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;high data=\&quot;30\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;icon data=\&quot;/ig/images/weather/chance_of_rain.gif\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;condition data=\&quot;&#x53EF;&#x80FD;&#x6709;&#x96E8;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;/forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;day_of_week data=\&quot;&#x5468;&#x56DB;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;low data=\&quot;25\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;high data=\&quot;29\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;icon data=\&quot;/ig/images/weather/thunderstorm.gif\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;condition data=\&quot;&#x96F7;&#x9635;&#x96E8;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;/forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;day_of_week data=\&quot;&#x5468;&#x4E94;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;low data=\&quot;24\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;high data=\&quot;31\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;icon data=\&quot;/ig/images/weather/chance_of_storm.gif\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;            &lt;condition data=\&quot;&#x53EF;&#x80FD;&#x6709;&#x66B4;&#x98CE;&#x96E8;\&quot;/&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;        &lt;/forecast_conditions&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;    &lt;/weather&gt;\n&quot;</span> +
        <span class="hljs-string">&quot;&lt;/xml_api_reply&gt;&quot;</span>;
</code></pre>
<h2 id="1-dom&#x65B9;&#x5F0F;">1 DOM&#x65B9;&#x5F0F;</h2>
<ul>
<li>DOM<ul>
<li>DOM&#x65B9;&#x5F0F;&#x89E3;&#x6790;xml&#x662F;&#x5148;&#x628A;xml&#x6587;&#x6863;&#x90FD;&#x8BFB;&#x5230;&#x5185;&#x5B58;&#x4E2D;</li>
<li>&#x5982;&#x679C;XML&#x6587;&#x4EF6;&#x5F88;&#x5927;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5904;&#x7406;&#x6548;&#x7387;&#x5C31;&#x4F1A;&#x53D8;&#x5F97;&#x6BD4;&#x8F83;&#x4F4E;</li>
</ul>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-comment">//&#x4F7F;&#x7528;InputStream&#x6216;&#x8005;String&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;org.w3c.dom.Document&#x5BF9;&#x8C61;&#xFF0C;&#x4EE3;&#x8868;&#x4E00;&#x4E2A;xml&#x6587;&#x6863;&#x7684;DOM&#x6811;</span>
<span class="hljs-comment">//&#x7528;&#x5B57;&#x7B26;&#x4E32;xml</span>
javax.xml.parsers.DocumentBuilder myDocBuilder = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document document = myDocBuilder.parse(<span class="hljs-keyword">new</span> InputSource(<span class="hljs-keyword">new</span> StringReader(xml&#x5B57;&#x7B26;&#x4E32;)));

<span class="hljs-comment">//&#x7528;InputStream</span>
javax.xml.parsers.DocumentBuilder myDocBuilder = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document document = myDocBuilder.parse(<span class="hljs-keyword">new</span> InputSource(inputStream));

<span class="hljs-comment">//&#x7528;&#x672C;&#x5730;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;</span>
String path = <span class="hljs-string">&quot;file:///data/data/com.example.androiddemo/network.xml&quot;</span>
javax.xml.parsers.DocumentBuilder myDocBuilder = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document document = myDocBuilder.parse(path);

<span class="hljs-comment">//&#x83B7;&#x53D6;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x4EE5;&#x6839;&#x8282;&#x70B9;&#x4E3A;&#x8D77;&#x59CB;&#xFF0C;&#x8BBF;&#x95EE;&#x5176;&#x4ED6;&#x5B50;&#x8282;&#x70B9;</span>
Element root=document.getDocumentElement();

<span class="hljs-comment">//&#x83B7;&#x53D6;&#x67D0;&#x4E2A;&#x6807;&#x7B7E;&#x5BF9;&#x5E94;&#x7684;&#x6240;&#x6709;&#x5B50;&#x8282;&#x70B9;</span>
NodeList nodes=root.getElementsByTagName(<span class="hljs-string">&quot;forecast_conditions&quot;</span>);

<span class="hljs-comment">//&#x904D;&#x5386;&#x5B50;&#x8282;&#x70B9;&#x5217;&#x8868;</span>
<span class="hljs-comment">//&#x89E3;&#x6790;&#x51FA;&#x672A;&#x6765;5&#x5929;&#x7684;&#x5929;&#x6C14;&#x9884;&#x62A5;</span>
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; nodes.getLength(); i++){
    <span class="hljs-comment">//&#x8FD9;&#x662F;&#x4E00;&#x4E2A;forecast_conditions&#x6807;&#x7B7E;</span>
    Node node = nodes.item(i);
    Log.i(<span class="hljs-string">&quot;dom&quot;</span>, <span class="hljs-string">&quot;==============begin&#xFF1A;&quot;</span> + node.getNodeName());
    NodeList children = node.getChildNodes();
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> j = <span class="hljs-number">0</span>; j &lt; children.getLength(); j++){
        <span class="hljs-comment">//&#x904D;&#x5386;&#x5B50;&#x8282;&#x70B9;</span>
        Node n = children.item(j);
        Log.i(<span class="hljs-string">&quot;dom&quot;</span>, <span class="hljs-string">&quot;&#x5B50;&#x8282;&#x70B9;&#xFF1A;&quot;</span> + n.getNodeName() + <span class="hljs-string">&quot;==&gt;&quot;</span> + n.getNodeValue());
        NamedNodeMap attrs = n.getAttributes();
        <span class="hljs-keyword">if</span>(attrs != <span class="hljs-keyword">null</span>){
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> k = <span class="hljs-number">0</span>; k &lt; attrs.getLength(); k++){
                <span class="hljs-comment">//&#x904D;&#x5386;attr</span>
                Log.i(<span class="hljs-string">&quot;dom&quot;</span>, <span class="hljs-string">&quot;----&quot;</span> + attrs.item(k).getNodeName() + <span class="hljs-string">&quot;==&gt;&quot;</span> + attrs.item(k).getNodeValue());
            }
        }
    }
    Log.i(<span class="hljs-string">&quot;dom&quot;</span>, <span class="hljs-string">&quot;==============over\n\n&quot;</span>);
}

<span class="hljs-comment">//&#x6CE8;&#x610F;&#xFF0C;&#x8001;&#x662F;&#x6709;&#x4E2A;&#x540D;&#x4E3A;#text&#x7684;&#x5B50;&#x8282;&#x70B9;&#xFF0C;value&#x8FD8;&#x662F;&#x7A7A;&#xFF0C;&#x4E5F;&#x6CA1;&#x6709;&#x5C5E;&#x6027;&#xFF0C;&#x5C1D;&#x8BD5;&#x53BB;&#x6389;&#x7A7A;&#x683C;&#x548C;&#x6362;&#x884C;&#xFF0C;&#x8FD8;&#x62A5;&#x9519;</span>
</code></pre>
<h2 id="2-sax&#x65B9;&#x5F0F;">2 SAX&#x65B9;&#x5F0F;</h2>
<ul>
<li>sax&#xFF1A;<ul>
<li>&#x901F;&#x5EA6;&#x66F4;&#x5FEB;&#xFF0C;&#x66F4;&#x6709;&#x6548;&#xFF0C;&#x5360;&#x7528;&#x5185;&#x5B58;&#x66F4;&#x5C11;</li>
<li>&#x9010;&#x884C;&#x626B;&#x63CF;&#xFF0C;&#x53EF;&#x4EE5;&#x505A;&#x5230;&#x8FB9;&#x626B;&#x63CF;&#x8FB9;&#x89E3;&#x6790;</li>
<li>SAX &#x53EF;&#x4EE5;&#x5728;&#x89E3;&#x6790;&#x6587;&#x6863;&#x7684;&#x4EFB;&#x610F;&#x65F6;&#x523B;&#x505C;&#x6B62;&#x89E3;&#x6790;&#xFF0C;&#x975E;&#x5E38;&#x9002;&#x7528;&#x4E8E; Android &#x7B49;&#x79FB;&#x52A8;&#x8BBE;&#x5907;</li>
<li>&#x57FA;&#x4E8E;&#x4E8B;&#x4EF6;&#x9A71;&#x52A8;</li>
<li>&#x4E0D;&#x7528;&#x89E3;&#x6790;&#x5B8C;&#x6574;&#x4E2A;&#x6587;&#x6863;&#xFF0C;&#x5728;&#x6309;&#x5185;&#x5BB9;&#x987A;&#x5E8F;&#x89E3;&#x6790;&#x6587;&#x6863;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C; SAX &#x4F1A;&#x5224;&#x65AD;&#x5F53;&#x524D;&#x8BFB;&#x5230;&#x7684;&#x5B57;&#x7B26;&#x662F;&#x5426;&#x7B26;&#x5408; XML &#x6587;&#x4EF6;&#x8BED;&#x6CD5;&#x4E2D;&#x7684;&#x67D0;&#x90E8;&#x5206;&#x3002;&#x5982;&#x679C;&#x7B26;&#x5408;&#x67D0;&#x90E8;&#x5206;&#xFF0C;&#x5219;&#x4F1A;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;</li>
<li>&#x6240;&#x8C13;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;&#xFF0C;&#x5C31;&#x662F;&#x8C03;&#x7528;&#x4E00;&#x4E9B;&#x56DE;&#x8C03;&#x65B9;&#x6CD5;</li>
<li>&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x5668;&#x662F; org.xml.sax &#x5305;&#x4E2D; ContentHander &#x3001; DTDHander &#x3001; ErrorHandler &#xFF0C;&#x4EE5;&#x53CA; EntityResolver &#x8FD9; 4 &#x4E2A;&#x63A5;&#x53E3;<ul>
<li>ContentHander&#xFF1A;setContentHandler(ContentHandler h)&#xFF0C;XML &#x6587;&#x6863;&#x6807;&#x7B7E;&#x7684;&#x5F00;&#x59CB;&#x4E0E;&#x7ED3;&#x675F;&#xFF0C;&#x63A5;&#x6536;&#x5B57;&#x7B26;&#x6570;&#x636E;&#xFF0C;&#x8DF3;&#x8FC7;&#x5B9E;&#x4F53;&#xFF0C;&#x63A5;&#x6536;&#x5143;&#x7D20;&#x5185;&#x5BB9;&#x4E2D;&#x53EF;&#x5FFD;&#x7565;&#x7684;&#x7A7A;&#x767D;&#x7B49;</li>
<li>DTDHander&#xFF1A;setDTDHandler(DTDHandler h)&#xFF0C;&#x5904;&#x7406; DTD &#x89E3;&#x6790;&#x65F6;&#x4EA7;&#x751F;&#x7684;&#x76F8;&#x5E94;&#x4E8B;&#x4EF6;</li>
<li>ErrorHandler&#xFF1A;setErrorHandler(ErrorHandler h)&#xFF0C;&#x5904;&#x7406; XML &#x6587;&#x6863;&#x65F6;&#x4EA7;&#x751F;&#x7684;&#x9519;&#x8BEF;</li>
<li>EntityResolver&#xFF1A;setEntityResolver(EntityResolver e)&#xFF0C;&#x5904;&#x7406;&#x5916;&#x90E8;&#x5B9E;&#x4F53;</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li>&#x5173;&#x4E8E;ContentHandler&#xFF1A;<ul>
<li>startDocument() &#xFF0C;&#x5F53;&#x9047;&#x5230;&#x6587;&#x6863;&#x7684;&#x5F00;&#x5934;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x5176;&#x4E2D;&#x505A;&#x4E00;&#x4E9B;&#x9884;&#x5904;&#x7406;&#x7684;&#x5DE5;&#x4F5C;</li>
<li>endDocument()&#xFF0C;&#x5F53;&#x6587;&#x6863;&#x7ED3;&#x675F;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x5176;&#x4E2D;&#x505A;&#x4E00;&#x4E9B;&#x5584;&#x540E;&#x7684;&#x5DE5;&#x4F5C;</li>
<li>startElement(String namespaceURI, String localName,String qName, Attributes atts)<ul>
<li>&#x5F53;&#x8BFB;&#x5230;&#x5F00;&#x59CB;&#x6807;&#x7B7E;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;</li>
<li>namespaceURI &#x5C31;&#x662F;&#x547D;&#x540D;&#x7A7A;&#x95F4;</li>
<li>localName &#x662F;&#x4E0D;&#x5E26;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x524D;&#x7F00;&#x7684;&#x6807;&#x7B7E;&#x540D;</li>
<li>qName &#x662F;&#x5E26;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x524D;&#x7F00;&#x7684;&#x6807;&#x7B7E;&#x540D;</li>
<li>&#x901A;&#x8FC7; atts &#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x6240;&#x6709;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x548C;&#x76F8;&#x5E94;&#x7684;&#x503C;</li>
</ul>
</li>
<li>endElement(String uri, String localName, String name)&#xFF0C;&#x5728;&#x9047;&#x5230;&#x7ED3;&#x675F;&#x6807;&#x7B7E;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;</li>
<li>characters(char[] ch, int start, int length)<ul>
<li>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7528;&#x6765;&#x5904;&#x7406;&#x5728; XML &#x6587;&#x4EF6;&#x4E2D;&#x8BFB;&#x5230;&#x7684;&#x5185;&#x5BB9;&#x3002;&#x4F8B;&#x5982;&#xFF1A; <high data="30"> &#x4E3B;&#x8981;&#x76EE;&#x7684;&#x662F;&#x83B7;&#x53D6; high &#x6807;&#x7B7E;&#x4E2D;&#x7684;&#x503C;</high></li>
<li>&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7528;&#x4E8E;&#x5B58;&#x653E;&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;</li>
<li>&#x540E;&#x9762;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8BFB;&#x5230;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5728;&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x8D77;&#x59CB;&#x4F4D;&#x7F6E;&#x548C;&#x957F;&#x5EA6;&#xFF0C;&#x4F7F;&#x7528; new String(ch,start,length) &#x5C31;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5185;&#x5BB9;</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&#x793A;&#x4F8B;&#xFF1A;
&lt;?xml version=&quot;1.0&quot;?&gt;</p>
<p><weather>              ----------&gt;         startElement</weather></p>
<p><forecast_information> ----------&gt;         startElement</forecast_information></p>
<p><city>                 ----------&gt;         startElement</city></p>
<p>beijing                ----------&gt;        characters</p>
<p>&lt;/city&gt;                ----------&gt;        endElement</p>
<p>&lt;/forecast_information &gt; ----------&gt;        endElement</p>
<p>&lt;/weather &gt;            ----------&gt;        endElement</p>
<p>&#x6587;&#x6863;&#x7ED3;&#x675F;                ----------&gt;        endDocument()</p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">parseBySax</span><span class="hljs-params">()</span></span>{
    <span class="hljs-keyword">try</span> {
        SAXParserFactory saxFactory = SAXParserFactory.newInstance();
        SAXParser saxParser = saxFactory.newSAXParser();<span class="hljs-comment">//&#x5229;&#x7528;&#x83B7;&#x53D6;&#x5230;&#x7684;&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x89E3;&#x6790;&#x5668;</span>

        <span class="hljs-comment">//parse&#x65B9;&#x5F0F;1</span>
        XMLContentHandler handler = <span class="hljs-keyword">new</span> XMLContentHandler();<span class="hljs-comment">//&#x8BBE;&#x7F6E;defaultHandler</span>
        StringReader r = <span class="hljs-keyword">new</span> StringReader(xml);
        saxParser.parse(<span class="hljs-keyword">new</span> InputSource(r), handler);<span class="hljs-comment">//&#x8FDB;&#x884C;&#x89E3;&#x6790;</span>
        r.close();
        <span class="hljs-comment">/* parse&#x65B9;&#x5F0F;2
        XMLReader xmlReader =saxFactory.newSAXParser().getXMLReader(); //&#x83B7;&#x53D6;&#x4E00;&#x4E2A;XMLReader
        xmlReader.setContentHandler(handler);
        xmlReader.parse(newInputSource(stream));
        */</span>

    } <span class="hljs-keyword">catch</span> (Exception e) {
        e.printStackTrace();
    }
}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">XMLContentHandler</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">DefaultHandler</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String TAG = <span class="hljs-string">&quot;XMLContentHandler&quot;</span>;

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">characters</span><span class="hljs-params">(<span class="hljs-keyword">char</span>[] ch, <span class="hljs-keyword">int</span> start, <span class="hljs-keyword">int</span> length)</span>
            <span class="hljs-keyword">throws</span> SAXException </span>{
        Log.i(TAG, <span class="hljs-string">&quot;&#x89E3;&#x6790;&#x5185;&#x5BB9;&#xFF1A;&quot;</span>+<span class="hljs-keyword">new</span> String(ch,start,length));
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">endDocument</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> SAXException </span>{
        <span class="hljs-keyword">super</span>.endDocument();
        Log.i(TAG, <span class="hljs-string">&quot;&#x6587;&#x6863;&#x89E3;&#x6790;&#x5B8C;&#x6BD5;&#x3002;&quot;</span>);
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">endElement</span><span class="hljs-params">(String uri, String localName, String qName)</span>
            <span class="hljs-keyword">throws</span> SAXException </span>{
        Log.i(TAG, localName+<span class="hljs-string">&quot;&#x89E3;&#x6790;&#x5B8C;&#x6BD5;&quot;</span>);
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">startDocument</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> SAXException </span>{
        Log.i(TAG, <span class="hljs-string">&quot;&#x5F00;&#x59CB;&#x89E3;&#x6790;... ...&quot;</span>);
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">startElement</span><span class="hljs-params">(String uri, String localName, String qName,
                             Attributes attributes)</span> <span class="hljs-keyword">throws</span> SAXException </span>{
        Log.i(TAG, <span class="hljs-string">&quot;&#x89E3;&#x6790;&#x5143;&#x7D20;&#xFF1A;&quot;</span>+localName);

        <span class="hljs-keyword">if</span>(localName.equals(<span class="hljs-string">&quot;high&quot;</span>)){
            Log.i(TAG, <span class="hljs-string">&quot;&#x89E3;&#x6790;&#x5143;&#x7D20;&#xFF1A;&quot;</span>+localName);
            <span class="hljs-keyword">if</span>(attributes != <span class="hljs-keyword">null</span>){
                <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; attributes.getLength(); i++){
                    Log.i(TAG, <span class="hljs-string">&quot;====&quot;</span> + attributes.getLocalName(i) + <span class="hljs-string">&quot;: &quot;</span> + attributes.getQName(i) + <span class="hljs-string">&quot;: &quot;</span> + attributes.getValue(i));
                }
            }
        }
    }
}
</code></pre>
<h2 id="3-pull">3 PULL</h2>
<p><a href="http://www.tuicool.com/articles/IvQvyq" target="_blank">http://www.tuicool.com/articles/IvQvyq</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="http.html" class="navigation navigation-prev " aria-label="Previous page: http">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="json-reporter.html" class="navigation navigation-next " aria-label="Next page: Json解析">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"xml解析","level":"2.5","depth":1,"next":{"title":"Json解析","level":"2.6","depth":1,"path":"json-reporter.md","ref":"json-reporter.md","articles":[]},"previous":{"title":"http","level":"2.4","depth":1,"path":"http.md","ref":"http.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"xml.md","mtime":"2017-04-09T14:39:34.177Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-09T17:03:25.521Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

